//
//  MapViewController.m
//  MiaoTu
//
//  Created by dllo on 16/9/24.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "MapViewController.h"
@import MapKit;
@import CoreLocation;

@interface MapViewController ()
@property (nonatomic, strong) MKMapView *mapView;
@end

@implementation MapViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.mapView = [[MKMapView alloc] initWithFrame:self.view.bounds];
    
    CLGeocoder *geocoder = [CLGeocoder new];
    [geocoder geocodeAddressString:_addressString completionHandler:^(NSArray<CLPlacemark *> * _Nullable placemarks, NSError * _Nullable error) {
        CLPlacemark *firstPlace = placemarks[0];
        MKPlacemark *mapPlacemark = [[MKPlacemark alloc] initWithPlacemark:firstPlace];
        [self.mapView addAnnotation:mapPlacemark];        
        MKCoordinateRegion mapRegion;
        mapRegion.center.latitude = mapPlacemark.location.coordinate.latitude;
        mapRegion.center.longitude = mapPlacemark.location.coordinate.longitude;
        mapRegion.span.latitudeDelta = 0.005;
        mapRegion.span.longitudeDelta = 0.005;
        [_mapView setRegion:mapRegion animated:NO];
    }];
    
    [self.view addSubview:_mapView];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
